function parse_url(){
	var param = location.search;
	var theRequest = Object();
	if (param.indexOf("?") != -1) {
		var str = param.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i ++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
function select_area(){
	if($("#search_type").val() == 3){
        $("#keyword").css('display' , 'none');
		$("#province").css("display","");
		$("#city").css("display","");
	}else{
        $("#keyword").css('display' , '');
		$("#province").css("display","none");
		$("#city").css("display","none");
	}
}
$(document).ready(function(){
	select_area();
	//搜索条件
	$(".selectthis").click(function(){
		var url = location.href;
		var def_param = parse_url();
		var link = $(this);
		var param = '';
		var x;
		def_param[link.attr("rel")] = link.attr("val");
		def_param['stime'] = $('#stime').val();
		def_param['etime'] = $('#etime').val();
		for(x in def_param){
			param = param + '&' + x + '=' + def_param[x];
		}
		param = param.substr(1);
		url = url.split("?")[0] + '?' + param;
		location.href = url;
	});
	//搜索框
	$("#search_all").click(function(){
		var url = location.href;
		var def_param = parse_url();
		def_param['stime'] = $('#stime').val();
		def_param['etime'] = $('#etime').val();
		def_param['search_type'] = $('#search_type').val();
		def_param['keyword'] = $('#keyword').val();
		if($("#search_type").val() == 3){
			def_param['province'] = $('#province').val();
			def_param['city'] = $('#city').val();
		}
		var param = '';
		var x;
		for(x in def_param){
			if(def_param[x] != ''){
				param = param + '&' + x + '=' + def_param[x];
			}
		}
		param = param.substr(1);
		url = url.split("?")[0] + '?' + param;
		location.href = url;
	});
	//搜索select
	$("#search_type").change(function(){
		select_area();
	});
 	$("#pagesize").change(function(){
		var url = location.href;
		var def_param = parse_url();
		def_param['pagesize'] = $("#pagesize").val();	
		var param = '';
		var x;
		for(x in def_param){
			if(def_param[x] != ''){
				param = param + '&' + x + '=' + def_param[x];
			}
		}
		param = param.substr(1);
		url = url.split("?")[0] + '?' + param;
		location.href = url;
	});
});